package game.windows;

import game.shared.Constants;
import game.shared.Resources;

import java.util.ArrayList;

import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;

public class Form extends WindowControl{
	
	String title;
	TextureRegion watermark;
	boolean bDrawWatermark;
	ArrayList<WindowControl> listItems;

	public void setbDrawWatermark(boolean bDrawWatermark) {
		this.bDrawWatermark = bDrawWatermark;
	}
	
	public void addControl(WindowControl control)
	{
		control.setXY(x + control.getX(), y + control.getY());
		listItems.add(control);
	}
	
	public void update()
	{
		for (WindowControl item : listItems) {
			item.update();
		}
//		dispatchMessage();
	}
	
	public void update(int idGroup){
		for (WindowControl item : listItems){
			if (item.idGroup == idGroup)
				item.update();
		}
	}
		
	
//	private void dispatchMessage() {
//		int f = Constants.get_RETURN_CODE();
//		switch (f) {
//		case Constants.FUNCTION_CODE_EXIT:
//			Constants.set_RETURN_CODE(Constants.FUNCTION_CODE_RESUME);
//			break;
//		default: 
//			Constants.set_RETURN_CODE(f);
//			break;
//		}
//	}

	public void render(SpriteBatch sb)
	{
		if(bDrawWatermark)
			sb.draw(watermark, 0, 0, Constants.SCREEN_WIDTH, Constants.SCREEN_HEIGHT);
		
		for (WindowControl item : listItems) {
			item.render(sb);
		}
	}
	
	public void render(int idGroup, SpriteBatch sb)
	{
		for (WindowControl item : listItems) {
			if (item.idGroup == idGroup)
				item.render(sb);
		}
	}
	
	public void dispath()
	{		
	}
	
	public Form() {
		listItems = new ArrayList<WindowControl>();
		watermark = Resources.getTextureRegion(Resources.WATERMARK);
	}
}
